#ifndef __AGORA_NETWORK_CONNECTION_H__
#define __AGORA_NETWORK_CONNECTION_H__

#include <string>
#include "winsock2.h"

namespace Network
{
	class	Connection
	{
	public:
		Connection();
#ifdef _WIN32
		Connection(const std::string& address, unsigned short int port, SOCKET socket, SOCKADDR_IN socketInfos);
#else
		Connection(const std::string& address, unsigned short int port, unsigned int socket, sockaddr_in socketInfos);
#endif
		~Connection();
		unsigned int		CloseSocket();
		unsigned int		ReceiveData(void* data, unsigned int* size, timeval* timeout = NULL);
		unsigned int		SendData(void* data, unsigned int* size, timeval* timeout = NULL);
		const std::string&	GetAddress() const;
		unsigned short int	GetPort() const;
	protected:
		unsigned int		CreateSocket();
		unsigned int		BindSocket(unsigned short int port, const std::string& address = "ANYADDR");

		std::string			_address;
		unsigned short int	_port;
#ifdef _WIN32
		SOCKET				_socket;
		SOCKADDR_IN			_socketInfos;
#else
		unsigned int		_socket;
		sockaddr_in			_socketInfos;
#endif
		int					_socketInfosLenght;
	};
}

#endif